﻿<?php
include('lib/include.php');
session_start();

// default user info
$userinfo = array(
	'id'=>'',
	'contact_name'=>'',
	'company_name'=>'',
	'hst_number'=>'',
	'company_address'=>'',
	'company_city'=>'',
	'company_province'=>'',
	'company_postal_code'=>'',
	'company_phone_number'=>'',
	'company_fax_number'=>'',
	'company_email'=>'',
	'password'=>''
);

// default action variable
$action = 'create';

// create new
if (isset($_POST['action'])){
	if ($_POST['action'] == 'create'){
		$user = array(
			'contact_name'=>$_POST['contact_name'],
			'company_name'=>$_POST['company_name'],
			'hst_number'=>$_POST['hst_number'],
			'company_address'=>$_POST['company_address'],
			'company_city'=>$_POST['company_city'],
			'company_province'=>$_POST['company_province'],
			'company_postal_code'=>$_POST['company_postal_code'],
			'company_phone_number'=>$_POST['company_phone_number'],
			'company_fax_number'=>$_POST['company_fax_number'],
			'company_email'=>$_POST['company_email'],
			'password'=>$_POST['password'],
		);
		
		$res = addUser($user);
		//print(mysql_error());
		if ($res == $EMAILDUP_ERROR){
			$_SESSION['message'] = 'Email is existing. Please confirm and try again later.';
			redirect('message.php');
		}
		else if ($res) {
			$content = 'Thank you  for creating your profile, below is your log information. <br/>
									<br/>
									User name: '.$_POST['company_email'].'<br/>
									Password: '.$_POST['password'].'<br/>
									<br/>';

			/*
			if (sendMail($_POST['email'],$SENDER,'New account',$content)){
			*/
				$_SESSION['message'] = '<p class=\'style1\'>Your account has been created! </p>';
				redirect('message.php');
			/*}
			else {
				$_SESSION['message'] = 'Failed Registration. Please try again.';
				redirect('message.php');
			}*/
		}
		else {
			$_SESSION['message'] = 'Failed Registration. Please try again..';
			redirect('message.php');
		}
	}
	else if ($_POST['action'] == 'edit'){
		$user = array(
			'ContactName'=>$_POST['realname'],
			'DoctorName'=>$_POST['doctor'],
			'CompanyName'=>$_POST['company'],
			'FullAddress'=>$_POST['address'],
			'City'=>$_POST['city'],
			'Province'=>$_POST['province'],
			'PostalCode'=>$_POST['postal'],
			'PhoneNumber'=>$_POST['phone'],
			'FaxNumber'=>$_POST['fax'],
			'Email'=>$_POST['email'],
			'MethodPayment'=>$_POST['payment'],
			'Password'=>$_POST['password'],
			'Block'=>0
		);
		
		$res = updateUserById($_SESSION['userinfo']['ID'],$user);
		if ($res == false){
			$_SESSION['message'] = 'Update was not successful. Please try again.';
			redirect('message.php');
		}
		else {
			$_SESSION['message'] = 'Update was successful.';
			redirect('message.php');
		}
	}
}

// load user
if (isset($_GET['action'])){
	if ($_GET['action'] == 'load'){
		if (isset($_SESSION['userinfo'])){
			$user = getUserById($_SESSION['userinfo']['ID']);
			if ($user == false){
				$_SESSION['message'] = 'Could not find user.';
				redirect('message.php');
			}
			else {
				$userinfo['ID']=$user['ID'];
				$userinfo['ContactName']=$user['ContactName'];
				$userinfo['DoctorName']=$user['DoctorName'];
				$userinfo['CompanyName']=$user['CompanyName'];
				$userinfo['FullAddress']=$user['FullAddress'];
				$userinfo['City']=$user['City'];
				$userinfo['Province']=$user['Province'];
				$userinfo['PostalCode']=$user['PostalCode'];
				$userinfo['PhoneNumber']=$user['PhoneNumber'];
				$userinfo['FaxNumber']=$user['FaxNumber'];
				$userinfo['Email']=$user['Email'];
				$userinfo['MethodPayment']=$user['MethodPayment'];
				$userinfo['Password']=$user['Password'];
				$userinfo['Block']=$user['Block'];
				
				$action = 'edit';
			}
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>888 Accessories</title>

<meta name="keywords" content="" />

<meta name="description" content="" />

<link rel="shortcut icon" href="favicon.ico">

<link rel="stylesheet" type="text/css" href="css/css.css" />

<style type="text/css">
<!--
.style2 {
	font-size: 12px;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #FF0000;
}
-->
</style>

<script language="javascript">
function onsub(){
	if (document.getElementById('contact_name').value == ''){
		alert('Contact Name is required.');
		return false;
	}
	
	if (document.getElementById('company_name').value == ''){
		alert("Company Name is required.");
		return false;
	}

	if (document.getElementById('hst_number').value == ''){
		alert('HST number is required.');
		return false;
	}

	if (document.getElementById('company_address').value == ''){
		alert('Company Address is required.');
		return false;
	}

	if (document.getElementById('company_city').value == ''){
		alert('City is required.');
		return false;
	}

	if (document.getElementById('company_province').value == ''){
		alert('Province is required.');
		return false;
	}

	if (document.getElementById('company_postal_code').value == ''){
		alert('Postal Code is required.');
		return false;
	}
	else {
		var pattern = /^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$/i;
		if (document.getElementById('company_postal_code').value.match(pattern) == null){
			alert('Postal code is incorrect. Please try again.');
			return false;
		}
	}

	if (document.getElementById('company_phone_number').value == ''){
		alert('Phone Number is required.');
		return false;
	}
	else {
		var pattern = /^[2-9]\d{2}-\d{3}-\d{4}$/i;
		if (document.getElementById('company_phone_number').value.match(pattern) == null){
			alert('Phone Number requires dashes (-) between Area Code and Phone Number. Please try again.');
			return false;
		}
	}

	if (document.getElementById('company_fax_number').value != ''){
		var pattern = /^[2-9]\d{2}-\d{3}-\d{4}$/i;
		if (document.getElementById('company_fax_number').value.match(pattern) == null){
			alert('Fax Number requires dashes (-) between Area Code and Phone Number. Please try again or leave it blank.');
			return false;
		}
	}
	
	if (document.getElementById('company_email').value == ''){
		alert('Email is required.');
		return false;
	}
	else {
		var pattern = /^[0-9a-z_][0-9a-z_\-.]*@[0-9a-z_][0-9a-z_\-.]*$/i;
		if (document.getElementById('company_email').value.match(pattern) == null){
			alert('Email has been entered wrong. Please try again.');
			return false;
		}
	}
	
	/*
	if (document.getElementById('payment').value == ''){
		alert('Method of Payment is required.');
		return false;
	}
	*/

	if (document.getElementById('password').value == ''){
		alert('Password is required.');
		return false;
	}
	
	return true;
}
</script>
</head>

<body>

<div id="main">

<div id="main1">

<div class="logo2"><img src="images/banner.jpg" width="1000" height="84" />

</div>

</div>

<div id="main2">

<div id="body1">

<table width="1000" border="0" cellpadding="0" cellspacing="10">

<!--DWLayoutTable-->

<tr>

<td width="234" rowspan="2" valign="top">

<div class="testimonials">

<img src="images/logo.jpg" width="225" height="300" /></div>

<br />

<div class="testimonials">
  
<div align="center">
<span class="body2text2">Search</span>
<label>
<input name="textfield" type="text" id="textfield" maxlength="5" />
</label>

<span class="style2">GO</span></div>

</div>

<br />

<div class="leftnav">

</div>

<table width="225" border="0" cellpadding="0" cellspacing="10">

<tr>

<td>

<div class="leftnav2">

<ul>

<li><a href="#">- Cell Phones</a></li>

<li><a href="#">- Cell Phone Accessories</a></li>
                
<li><a href="#">- Cell Phone Parts</a></li>
                
<li><a href="#">- LED Signs</a></li>
</ul>

</div>

</td>

</tr>

</table>

<div class="leftnav-2">

</div>

<table width="225" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->

<tr>

<td><img src="images/specials2.jpg" width="225" height="247" /></td>
</tr>
</table>

</td>

<td width="742" height="17" align="center" valign="top" bgcolor="#F4F4F4">

<div id="menu1">

<a href="#" >My Account</a>&nbsp;&nbsp;:&nbsp;&nbsp;
<a href="#" >Basket</a>&nbsp;&nbsp;:&nbsp;&nbsp;
<a href="#" >Contact</a>
<a href="#" ></a>&nbsp;&nbsp;|&nbsp;&nbsp;
Click here to <a href="#">login</a> or <a href="#">create an account</a>&nbsp;&nbsp;|&nbsp;&nbsp;
Shopping Cart: <span class="style1">0</span> items - <span class="style1">$0.00</span>

</div>

</td>

</tr>

<tr>

<td rowspan="2" valign="top" class="body2">

<table width="89%" border="0" cellpadding="0" cellspacing="10">

<!--DWLayoutTable-->

<tr>

<td width="640" height="41" valign="top" class="body2text"><h1>Registration Page</h1></td>
</tr>

<tr>

<td height="705" valign="top" class="body2text2">

  <p align="justify">
    Please fill out the registration form below to begin navigating through our website and view our products and pricing. Please provide a working e-mail address and phone number for authentication purposes. Thank you.<br />
    <span class="style2">* - Mandatory Field</span>
    </p>
  
  <form action="registration.php" method="post" name="form1" id="form1" onsubmit="return onsub()">
	<input type="hidden" name="action" id="action" value="<?php print($action);?>">
    <table width="413"  border="0" align="center" cellpadding="0" cellspacing="6">
                        <!--DWLayoutTable-->
                      <tr align="left" valign="middle">
                        <td height="27" align="right" valign="middle" class="style31" scope="row"><span class="bodytext style4"><span class="style2">*</span>Contact Name:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="contact_name" type="text" id="contact_name" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                      <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle"> <span class="bodytext style4"><span class="style2">*</span>Company Name:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="company_name" type="text" id="company_name" size="25" maxlength="50" />
                        </td>
                      </tr>
                      <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4"><span class="style2">*</span>HST Number:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="hst_number" type="text" id="hst_number" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                      <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4"><span class="style2">*</span>Company Address:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="company_address" type="text" id="company_address" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                                            <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4"><span class="style2">*</span>City:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="company_city" type="text" id="company_city" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                                            <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4"><span class="style2">*</span>Province:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="company_province" type="text" id="company_province" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                                            <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4"><span class="style2">*</span>Postal Code:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="company_postal_code" type="text" id="company_postal_code" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                                            <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4"><span class="style2">*</span>Phone Number:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="company_phone_number" type="text" id="company_phone_number" size="25" maxlength="50" />
                        </td>
                      </tr>
                                            <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4">Fax Number:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="company_fax_number" type="text" id="company_fax_number" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                                            <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4"><span class="style2">*</span>Email:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="company_email" type="text" id="company_email" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                                            <tr align="left" valign="middle">
                        <td height="22" align="right" valign="middle" scope="row"><span class="bodytext style4"><span class="style2">*</span>Password:</span></td>
                        <td colspan="3" align="left" valign="middle"><input name="password" type="password" id="password" size="25" maxlength="50" />                        
                        </td>
                      </tr>
                      <tr align="center" valign="bottom">
                        <td height="24" align="center" valign="middle" scope="row">&nbsp;&nbsp; </td>
                        <td align="right" valign="middle" scope="row"><div align="right">
                            <input name="submit_button" type="submit" id="submit_button2" value="Send Form" />
                        </div></td>
                        <td valign="middle" scope="row"><div align="left">
                            <input name="Reset" type="reset" value="Clear Form" />
                        </div></td>
                        <td align="left" valign="middle" scope="row">&nbsp;</td>
                      </tr>
                    </table>
      </form>
  
</td>

</tr>

</table>          

</td>

</tr>

</table>

</div>

</div>

<div id="bottom"> 

<div class="bottom2">

<a href="requiring_a_mobile_locksmith.html" title="Requiring a Mobile Locksmith">HOME</a>&nbsp;&nbsp;|&nbsp;&nbsp;
<a href="ottawa_locksmith.html" title="Ottawa Locksmith">ABOUT US</a> &nbsp;&nbsp;|&nbsp;&nbsp;
<a href="finding_the_right_locksmith_online.html" title="Finding the right locksmith online">CATEGORIES</a>&nbsp;&nbsp;|&nbsp; 
<a href="keys_to_look_for_when_hiring_a_locksmith.html" title="Keys to look for when hiring a locksmith">CONTACT US</a>&nbsp;&nbsp;|&nbsp;&nbsp;
<a href="intercom_systems.html" title="Intercom Systems">MY ACCOUNT</a><a href="cornwall_locksmith.html" title="Cornwall Locksmith"></a><br /> 

<em><strong>&copy; 888 Accessories. All Rights Reserved</strong></em>

</div>

</div>

</div>

</body>

</html>